package models;

import java.sql.Date;

import javax.persistence.*;
import org.apache.commons.mail.EmailException;

import play.data.validation.*;
import play.db.jpa.Model;

@Entity
public class Invitation extends Model {
	@Required
	@ManyToOne
	private User          sender; // User that sent the Invitation, Tarek Sheasha
	@Required
	@ManyToOne
	private User          receiver; // User to receive the Invitation, Tarek Sheasha
	@Required
	private String        content; // Content of the Invitation, Tarek Sheasha
	@Required
	private Date	      date; // Date Request was Invitation, Tarek Sheasha
	@Required
	private String        status; // Status of Invitation (Pending, Accepted, Rejected), Tarek Sheasha
	
	private Role          assignedRole; //Role of User once invitation has been accepted, Tarek Sheasha
	@ManyToOne
	private Organization  assignedOrganization; //The Organization the user was invited to join, Tarek Sheasha
	@ManyToOne
	private Eentity assignedEntity; // The entity that should be assigned to the invited user, Doaa El Hawary
	
	
	

	/**
	 * Constructor for Invitation with a specific entity assigned to the invitee
	 *
	 * @author		Doaa El-Hawary
	 * @version		2011.0424
	 * @category	C1S7
	 */
	public  Invitation(User sender, User receiver, String content, Eentity assignedEntity) {
		this.sender         = sender;
		this.receiver       = receiver;
		this.content        = content;
		this.date           = new Date(new java.util.Date().getTime());
		this.assignedEntity = assignedEntity; 
		this.assignedRole 	= new Role(assignedEntity, "Memeber");
		this.assignedOrganization = assignedEntity.getOrganization();
		this.status         = "Pending"; //Tarek Sheasha
	}
	
	public Invitation(User sender, User receiver, String content) {
		this.sender   = sender;
		this.receiver = receiver;
		this.content  = content;
		this.date     = new Date(new java.util.Date().getTime());
		this.status   = "Pending"; // Tarek Sheasha
	}
		
	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public User getReceiver() {
		return receiver;
	}

	public void setReceiver(User receiver) {
		this.receiver = receiver;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Eentity getAssignedEntity() {
		return assignedEntity;
	}

	public void setAssignedEntity(Eentity assignedEntity) {
		this.assignedEntity = assignedEntity;
	}

	public Organization getAssignedOrganization() {
		return assignedOrganization;
	}

	public void setAssignedOrganization(Organization assignedOrganization) {
		this.assignedOrganization = assignedOrganization;
	}

	public Role getAssignedRole() {
		return assignedRole;
	}

	public void setAssignedRole(Role assignedRole) {
		this.assignedRole = assignedRole;
	}

}